package com.jgy.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jgy.annotation.SetLogValue;
import com.jgy.entity.Systemlog;
import com.jgy.entity.Systemlogexception;
import com.jgy.mapper.SystemlogMapper;
import com.jgy.mapper.SystemlogexceptionMapper;
import com.jgy.utils.CommonConstants;
import com.jgy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 姜光远
 * @date 2023/2/7 9:01
 */
@RestController
@RequestMapping("/log")
public class LogController {

    @Autowired
    private SystemlogMapper systemlogMapper;

    @Autowired
    private SystemlogexceptionMapper systemlogexceptionMapper;


    @GetMapping("/getTrueList")
    public R<?> getTrueList(@RequestParam(defaultValue = "1") Integer pageNum,
                         @RequestParam(defaultValue = "5") Integer pageSize,
                         @RequestParam(defaultValue = "") String search) {
        LambdaQueryWrapper<Systemlog> wrapper = Wrappers.<Systemlog>lambdaQuery();
        //if (StrUtil.isNotBlank(search)) {
            wrapper.like(true,Systemlog::getUsername, search);
            wrapper.orderByDesc(Systemlog::getCreatetime);
        //}
        Page<Systemlog> systemlogPage = systemlogMapper.selectPage(new Page<>(pageNum, pageSize), wrapper);
        return R.ok(systemlogPage);
    }
    @GetMapping("/getWarnList")
    public R<?> getWarnList(@RequestParam(defaultValue = "1") Integer pageNum,
                         @RequestParam(defaultValue = "10") Integer pageSize,
                         @RequestParam(defaultValue = "") String search) {
        LambdaQueryWrapper<Systemlogexception> wrapper = Wrappers.<Systemlogexception>lambdaQuery();
        if (StrUtil.isNotBlank(search)) {
            wrapper.like(Systemlogexception::getUsername, search);
        }
        Page<Systemlogexception> systemlogPage = systemlogexceptionMapper.selectPage(new Page<>(pageNum, pageSize), wrapper);
        return R.ok(systemlogPage);
    }
}
